package com.mac.hosp_pre.order.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mac.hosp_pre.order.enums.OrderStatusEnum;
import com.mac.hosp_pre.order.model.req.OrderCountQueryReqDto;
import com.mac.hosp_pre.order.model.req.OrderQueryReqDto;
import com.mac.hosp_pre.order.model.resp.OrderInfoRespDto;
import com.mac.hosp_pre.order.service.OrderService;
import com.mac.hosp_pre.reply.R;
import com.mac.hosp_pre.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Tag(name = "门户订单接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {

    @Autowired
    private OrderService orderService;

    @Operation(description = "生成挂号订单")
    @PostMapping("/submitOrder/{scheduleId}/{patientId}")
    public R savaOrders(@PathVariable String scheduleId,
                        @PathVariable Long patientId) {
        String orderCode = orderService.saveOrder(scheduleId,patientId);
        return R.success(orderCode);
    }

    @Operation(description = "根据订单id查询订单详情")
    @GetMapping("/getOrders/{orderId}")
    public R getOrders(@PathVariable String orderId) {
        OrderInfoRespDto respDto = orderService.getOrder(orderId);
        return R.success(respDto);
    }

    @Operation(description = "订单列表（条件查询带分页）")
    @GetMapping("/queryPage")
    public R list(@ParameterObject OrderQueryReqDto orderQueryVo, HttpServletRequest request) {
        //设置当前用户id
        orderQueryVo.setUserId(JwtUtil.getUserId(request));
        IPage<OrderInfoRespDto> respDtoIPage = orderService.selectPage(orderQueryVo);
        return R.success(respDtoIPage);
    }

    @Operation(description = "获取订单状态集合")
    @GetMapping("/getStatusList")
    public R getStatusList() {
        return R.success(OrderStatusEnum.getStatusList());
    }

    @Operation(description = "取消预约")
    @GetMapping("/cancelOrder/{orderId}")
    public R cancelOrder(@PathVariable Long orderId) {
        Boolean isOrder = orderService.cancelOrder(orderId);
        return R.success(isOrder);
    }

    @Operation(description = "获取订单统计数据")
    @PostMapping("/getCountMap")
    public R<Map<String, Object>> getCountMap(@RequestBody OrderCountQueryReqDto orderCountQuery) {
        return R.success(orderService.getCountMap(orderCountQuery));
    }
}



